import 'dart:convert';

T? asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class AcLoginModel {
  AcLoginModel({
    required this.isFirstRegister,
    required this.token,
    required this.userInfo,
  });

  factory AcLoginModel.fromJson(Map<String, dynamic> json) => AcLoginModel(
    isFirstRegister: asT<bool>(json['isFirstRegister'])!,
    token: asT<String>(json['token'])!,
    userInfo:
    Userinfo.fromJson(asT<Map<String, dynamic>>(json['userInfo'])!),
  );

  bool isFirstRegister;
  String token;
  Userinfo userInfo;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
    'isFirstRegister': isFirstRegister,
    'token': token,
    'userInfo': userInfo,
  };
}

class Userinfo {
  Userinfo({
    this.userId,
    this.nickname,
    this.avatar,
    this.avatarMapPath,
    this.gender,
    this.age,
    this.country,
    this.status,
    this.callCoins,
    this.unit,
    this.videoMapPaths,
    this.followNum,
    this.isFriend,
    this.isBlock,
    this.isMultiple,
    this.applicableTags,
    this.about,
    // 从第二个类中添加的字段
    this.auditStatus,
    this.availableCoins,
    this.avatarMiddleThumbUrl,
    this.avatarThumbUrl,
    this.avatarUrl,
    this.birthday,
    this.createTime,
    this.giftWallAction,
    this.hasEquity,
    this.isAnswer,
    this.isHavePassword,
    this.isInternal,
    this.isRecharge,
    this.isReview,
    this.isSwitchNotDisturbCall,
    this.isSwitchNotDisturbIm,
    this.isVip,
    this.level,
    this.loginPkgName,
    this.praiseNum,
    this.registerCountry,
    this.registerPkgName,
    this.rongcloudToken,
    this.tagDetails,
    this.tagsList,
    this.userType,
  });

  String? userId;
  String? nickname;
  String? avatar;
  String? avatarMapPath;
  int? gender;
  int? age;
  String? country;
  String? status;
  int? callCoins;
  String? unit;
  List<String>? videoMapPaths;
  int? followNum;
  bool? isFriend;
  bool? isBlock;
  bool? isMultiple;
  List<String>? applicableTags;
  String? about;
  // 从第二个类中添加的字段
  int? auditStatus;
  int? availableCoins;
  String? avatarMiddleThumbUrl;
  String? avatarThumbUrl;
  String? avatarUrl;
  String? birthday;
  dynamic createTime;
  int? giftWallAction;
  bool? hasEquity;
  bool? isAnswer;
  bool? isHavePassword;
  bool? isInternal;
  bool? isRecharge;
  bool? isReview;
  bool? isSwitchNotDisturbCall;
  bool? isSwitchNotDisturbIm;
  bool? isVip;
  int? level;
  String? loginPkgName;
  int? praiseNum;
  String? registerCountry;
  String? registerPkgName;
  String? rongcloudToken;
  List<Tagdetails>? tagDetails;
  List<String>? tagsList;
  int? userType;

  factory Userinfo.fromJson(Map<String, dynamic> json) {
    final List<String>? videoMapPaths =
    (json['videoMapPaths'] as List?)?.map((item) => item as String).toList();
    final List<String>? applicableTags =
    (json['applicableTags'] as List?)?.map((item) => item as String).toList();

    // 从第二个类中添加的字段的处理
    final List<Tagdetails>? tagDetails = (json['tagDetails'] as List?)
        ?.map((item) => Tagdetails.fromJson(item as Map<String, dynamic>))
        .toList();
    final List<String>? tagsList =
    (json['tagsList'] as List?)?.map((item) => item as String).toList();

    return Userinfo(
      userId: json['userId'] as String?,
      nickname: json['nickname'] as String?,
      avatar: json['avatar'] as String?,
      avatarMapPath: json['avatarMapPath'] as String?,
      gender: json['gender'] as int?,
      age: json['age'] as int?,
      country: json['country'] as String?,
      status: json['status'] as String?,
      callCoins: json['callCoins'] as int?,
      unit: json['unit'] as String?,
      videoMapPaths: videoMapPaths,
      followNum: json['followNum'] as int?,
      isFriend: json['isFriend'] as bool?,
      isBlock: json['isBlock'] as bool?,
      isMultiple: json['isMultiple'] as bool?,
      applicableTags: applicableTags,
      about: json['about'] as String?,
      // 从第二个类中添加的字段
      auditStatus: json['auditStatus'] as int?,
      availableCoins: json['availableCoins'] as int?,
      avatarMiddleThumbUrl: json['avatarMiddleThumbUrl'] as String?,
      avatarThumbUrl: json['avatarThumbUrl'] as String?,
      avatarUrl: json['avatarUrl'] as String?,
      birthday: json['birthday'] as String?,
      createTime: json['createTime'],
      giftWallAction: json['giftWallAction'] as int?,
      hasEquity: json['hasEquity'] as bool?,
      isAnswer: json['isAnswer'] as bool?,
      isHavePassword: json['isHavePassword'] as bool?,
      isInternal: json['isInternal'] as bool?,
      isRecharge: json['isRecharge'] as bool?,
      isReview: json['isReview'] as bool?,
      isSwitchNotDisturbCall: json['isSwitchNotDisturbCall'] as bool?,
      isSwitchNotDisturbIm: json['isSwitchNotDisturbIm'] as bool?,
      isVip: json['isVip'] as bool?,
      level: json['level'] as int?,
      loginPkgName: json['loginPkgName'] as String?,
      praiseNum: json['praiseNum'] as int?,
      registerCountry: json['registerCountry'] as String?,
      registerPkgName: json['registerPkgName'] as String?,
      rongcloudToken: json['rongcloudToken'] as String?,
      tagDetails: tagDetails,
      tagsList: tagsList,
      userType: json['userType'] as int?,
    );
  }

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() {
    return <String, dynamic>{
      'userId': userId,
      'nickname': nickname,
      'avatar': avatar,
      'avatarMapPath': avatarMapPath,
      'gender': gender,
      'age': age,
      'country': country,
      'status': status,
      'callCoins': callCoins,
      'unit': unit,
      'videoMapPaths': videoMapPaths,
      'followNum': followNum,
      'isFriend': isFriend,
      'isBlock': isBlock,
      'isMultiple': isMultiple,
      'applicableTags': applicableTags,
      'about': about,
      // 从第二个类中添加的字段
      'auditStatus': auditStatus,
      'availableCoins': availableCoins,
      'avatarMiddleThumbUrl': avatarMiddleThumbUrl,
      'avatarThumbUrl': avatarThumbUrl,
      'avatarUrl': avatarUrl,
      'birthday': birthday,
      'createTime': createTime,
      'giftWallAction': giftWallAction,
      'hasEquity': hasEquity,
      'isAnswer': isAnswer,
      'isHavePassword': isHavePassword,
      'isInternal': isInternal,
      'isRecharge': isRecharge,
      'isReview': isReview,
      'isSwitchNotDisturbCall': isSwitchNotDisturbCall,
      'isSwitchNotDisturbIm': isSwitchNotDisturbIm,
      'isVip': isVip,
      'level': level,
      'loginPkgName': loginPkgName,
      'praiseNum': praiseNum,
      'registerCountry': registerCountry,
      'registerPkgName': registerPkgName,
      'rongcloudToken': rongcloudToken,
      'tagDetails': tagDetails?.map((x) => x.toJson()).toList(),
      'tagsList': tagsList,
      'userType': userType,
    };
  }
}


class Tagdetails {
  Tagdetails({
    required this.tag,
    required this.tagColor,
    required this.tagTip,
  });

  factory Tagdetails.fromJson(Map<String, dynamic> json) => Tagdetails(
    tag: asT<String>(json['tag'])!,
    tagColor: asT<String>(json['tagColor'])!,
    tagTip: asT<String>(json['tagTip'])!,
  );

  String tag;
  String tagColor;
  String tagTip;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
    'tag': tag,
    'tagColor': tagColor,
    'tagTip': tagTip,
  };
}
